package com.shop.mms_client.repository;

import android.content.Context;
import androidx.lifecycle.LiveData;
import com.shop.mms_client.db.AppDatabase;
import com.shop.mms_client.db.dao.MessageDao;
import com.shop.mms_client.model.Message;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MessageRepository {
    private static MessageRepository instance;
    private final MessageDao messageDao;
    private final ExecutorService executorService;

    private MessageRepository(Context context) {
        AppDatabase db = AppDatabase.getInstance(context);
        messageDao = db.messageDao();
        executorService = Executors.newSingleThreadExecutor();
    }

    public static synchronized MessageRepository getInstance(Context context) {
        if (instance == null) {
            instance = new MessageRepository(context);
        }
        return instance;
    }

    public void insertMessage(Message message) {
        executorService.execute(() -> messageDao.insert(message));
    }

    public LiveData<List<Message>> getAllMessages() {
        return messageDao.getAllMessages();
    }

    public LiveData<List<Message>> getSpamMessages() {
        return messageDao.getSpamMessages();
    }
} 